unit Class_DICT;

interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TDICT=class(TUniEngine)
  private
    FDICTINDX : Integer;
    FDICTCODE : string;
    FDICTNAME : string;
    FDICTMEMO : string;                   
    FCODELINK : string;
    FNAMELINK : string;
    FPARENTID : string;
    FDICTLEVL : Integer;
    FDICTORDR : Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIndx:Integer;overload;
    function  GetNextIndx(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property DICTINDX : Integer read FDICTINDX  write FDICTINDX;
    property DICTCODE : string read FDICTCODE  write FDICTCODE;
    property DICTNAME : string read FDICTNAME  write FDICTNAME;
    property DICTMEMO : string read FDICTMEMO  write FDICTMEMO;
    property CODELINK : string read FCODELINK  write FCODELINK;
    property NAMELINK : string read FNAMELINK  write FNAMELINK;
    property PARENTID : string read FPARENTID  write FPARENTID;
    property DICTLEVL : Integer read FDICTLEVL  write FDICTLEVL;
    property DICTORDR : Integer read FDICTORDR  write FDICTORDR;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ADICT:TDICT):TDICT;overload;        
    class procedure CopyIt(ADICT:TDICT;var Result:TDICT);overload;       
  end;

implementation

{ TDICT }
procedure TDICT.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('DICT_INDX').Value := DICTINDX;
        ParamByName('DICT_CODE').Value := DICTCODE;
        ParamByName('DICT_NAME').Value := DICTNAME;
        ParamByName('DICT_MEMO').Value := DICTMEMO;
        ParamByName('CODE_LINK').Value := CODELINK;
        ParamByName('NAME_LINK').Value := NAMELINK;
        ParamByName('PARENT_ID').Value := PARENTID;
        ParamByName('DICT_LEVL').Value := DICTLEVL;
        ParamByName('DICT_ORDR').Value := DICTORDR; 
      end;
      otEdit:
      begin
        ParamByName('DICT_INDX').Value := DICTINDX;
        ParamByName('DICT_CODE').Value := DICTCODE;
        ParamByName('DICT_NAME').Value := DICTNAME;
        ParamByName('DICT_MEMO').Value := DICTMEMO;
        ParamByName('CODE_LINK').Value := CODELINK;
        ParamByName('NAME_LINK').Value := NAMELINK;
        ParamByName('PARENT_ID').Value := PARENTID;
        ParamByName('DICT_LEVL').Value := DICTLEVL;
        ParamByName('DICT_ORDR').Value := DICTORDR; 
      end;  
      otDelt:
      begin
        ParamByName('DICT_INDX').Value := DICTINDX;
 
      end;  
    end;
  end;
end;

function TDICT.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_DICT',['DICT_INDX',DICTINDX],AUniConnection);
end;

function TDICT.GetNextIndx: Integer;
begin

end;

function TDICT.GetNextIndx(AUniConnection: TUniConnection): Integer;
begin

end;

function TDICT.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_DICT WHERE   DICT_INDX=:DICT_INDX';
end;

function TDICT.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_DICT'
         +'    ( DICT_INDX, DICT_CODE, DICT_NAME, DICT_MEMO, CODE_LINK'
         +'    , NAME_LINK, PARENT_ID, DICT_LEVL, DICT_ORDR)'
         +'    VALUES'
         +'    (:DICT_INDX,:DICT_CODE,:DICT_NAME,:DICT_MEMO,:CODE_LINK'
         +'    ,:NAME_LINK,:PARENT_ID,:DICT_LEVL,:DICT_ORDR)';
end;

function TDICT.GetStrsIndex: string;
begin
  Result:=Format('%D',[DICTINDX]);
end;

function TDICT.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_DICT SET'
         +'    DICT_CODE=:DICT_CODE,'
         +'    DICT_NAME=:DICT_NAME,'
         +'    DICT_MEMO=:DICT_MEMO,'
         +'    CODE_LINK=:CODE_LINK,'
         +'    NAME_LINK=:NAME_LINK,'
         +'    PARENT_ID=:PARENT_ID,'
         +'    DICT_LEVL=:DICT_LEVL,'
         +'    DICT_ORDR=:DICT_ORDR'
         +'    WHERE DICT_INDX=:DICT_INDX';
end;

constructor TDICT.Create;
begin

end;

destructor TDICT.Destroy;
begin

  inherited;
end;

class function TDICT.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TDICT.Create;

  with TDICT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='DICT_INDX' then
      begin
        DICTINDX :=Field.AsInteger;
      end else
      if FieldName='DICT_CODE' then
      begin
        DICTCODE :=Field.AsString;
      end else
      if FieldName='DICT_NAME' then
      begin
        DICTNAME :=Field.AsString;
      end else
      if FieldName='DICT_MEMO' then
      begin
        DICTMEMO :=Field.AsString;
      end else
      if FieldName='CODE_LINK' then
      begin
        CODELINK :=Field.AsString;
      end else
      if FieldName='NAME_LINK' then
      begin
        NAMELINK :=Field.AsString;
      end else
      if FieldName='PARENT_ID' then
      begin
        PARENTID :=Field.AsString;
      end else
      if FieldName='DICT_LEVL' then
      begin
        DICTLEVL :=Field.AsInteger;
      end else
      if FieldName='DICT_ORDR' then
      begin
        DICTORDR :=Field.AsInteger;
      end;
    end
  end;  
end;

class procedure TDICT.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TDICT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='DICT_INDX' then
      begin
        DICTINDX :=Field.AsInteger;
      end else
      if FieldName='DICT_CODE' then
      begin
        DICTCODE :=Field.AsString;
      end else
      if FieldName='DICT_NAME' then
      begin
        DICTNAME :=Field.AsString;
      end else
      if FieldName='DICT_MEMO' then
      begin
        DICTMEMO :=Field.AsString;
      end else
      if FieldName='CODE_LINK' then
      begin
        CODELINK :=Field.AsString;
      end else
      if FieldName='NAME_LINK' then
      begin
        NAMELINK :=Field.AsString;
      end else
      if FieldName='PARENT_ID' then
      begin
        PARENTID :=Field.AsString;
      end else
      if FieldName='DICT_LEVL' then
      begin
        DICTLEVL :=Field.AsInteger;
      end else
      if FieldName='DICT_ORDR' then
      begin
        DICTORDR :=Field.AsInteger;
      end;
    end
  end;  
end;

class function  TDICT.CopyIt(ADICT: TDICT): TDICT;
begin
  Result:=TDICT.Create;
  TDICT.CopyIt(ADICT,Result)
end;

class procedure TDICT.CopyIt(ADICT:TDICT;var Result:TDICT);
begin
  if Result=nil then Exit;
  Result.DICTINDX :=ADICT.DICTINDX;
  Result.DICTCODE :=ADICT.DICTCODE;
  Result.DICTNAME :=ADICT.DICTNAME;
  Result.DICTMEMO :=ADICT.DICTMEMO;
  Result.CODELINK :=ADICT.CODELINK;
  Result.NAMELINK :=ADICT.NAMELINK;
  Result.PARENTID :=ADICT.PARENTID;
  Result.DICTLEVL :=ADICT.DICTLEVL;
  Result.DICTORDR :=ADICT.DICTORDR;
end;

end.

